import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Admin from "@/views/admin/Admin";

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        component: HomeView,
        meta: {
            title: '玺玛特Xi-mart商城'
        }
    },
    {
        path: '/admin/login',
        component: () => import('../views/admin/AdminLoginView.vue'),
        meta: {
            title: '尔玉管理平台——管理员登录'
        }
    },
    {
        path: "/admin/reg",
        component: () => import('../views/admin/AdminRegView.vue'),
        meta: {
            title: '尔玉管理平台——管理员注册'
        }
    },
    {
        path: '/admin',
        component: Admin,
        redirect: '/admin/index',
        meta: {
            title: '尔玉后台管理平台'
        },
        children: [
            {
                path: "index",
                component: () => import('../views/admin/index/Index.vue'),
                meta: {
                    title: '尔玉管理平台——首页'
                }
            },
            {
                path: 'product/spumanage',
                name: 'product/spumanage',
                component: () => import('../views/admin/product/spu/SpuManage.vue'),
                meta: {
                    routerPath: 'spumanage'
                }
            },

            {
                path: 'product/skumanage/:id',
                name: 'product/skumanage',
                component: () => import('../views/admin/product/sku/SkuManage.vue'),
                meta: {
                    routerPath: 'spumanage'
                }
            },
            {
                path: 'product/addspu/1',
                name: 'product/addspu/1',
                component: () => import('../views/admin/product/spu/SpuAddStep1.vue'),
                meta: {
                    routerPath: 'addspu'
                }
            },
            {
                path: 'product/addspu/2',
                name: 'product/addspu/2',
                component: () => import('../views/admin/product/spu/SpuAddStep2.vue'),
                meta: {
                    routerPath: 'addspu'
                }
            },
            {
                path: 'product/addspu/3',
                name: 'product/addspu/3',
                component: () => import('../views/admin/product/spu/SpuAddStep3.vue'),
                meta: {
                    routerPath: 'addspu'
                }
            },
            {
                path: 'product/addspu/4',
                name: 'product/addspu/4',
                component: () => import('../views/admin/product/spu/SpuAddStep4.vue'),
                meta: {
                    routerPath: 'addspu'
                }
            },

            {
                path: 'product/albummanage',
                name: 'product/albummanage',
                component: () => import('../views/admin/product/album/AlbumManage.vue'),
                meta: {
                    routerPath: 'albummanage'
                }
            },
            {
                path: 'product/albummanage/:albumId',
                name: 'product/albummanage/albumId',
                component: () => import('../views/admin/product/album/PictureManage.vue'),
                meta: {
                    routerPath: 'albummanage'
                }
            },
            {
                path: 'product/category',
                name: 'product/category',
                component: () => import('../views/admin/product/category/CategoryManage.vue'),
                meta: {
                    routerPath: 'category'
                }
            },
            {
                path: 'product/addcategory',
                name: 'product/addcategory',
                component: () => import('../views/admin/product/category/CategoryAdd.vue'),
                meta: {
                    routerPath: 'category'
                }
            },
            {
                path: 'product/updatecategory',
                name: 'product/updatecategory',
                component: () => import('../views/admin/product/category/CategoryUpdate.vue'),
                meta: {
                    routerPath: 'category'
                }
            },
            {
                path: 'product/attributetemplatemanage',
                name: 'product/attributetemplatemanage',
                component: () => import('../views/admin/product/attribute/AttributeTemplateManage.vue'),
                meta: {
                    routerPath: 'attributetemplate'
                }
            },
            {
                path: 'product/nosalesattributemanage/:attributeTemplateId',
                name: 'product/nosalesattributemanage',
                component: () => import('../views/admin/product/attribute/NoSalesAttributeManage.vue'),
                meta: {
                    routerPath: 'attributetemplate'
                }
            },
            {
                path: 'product/addnosalesattribute/:attributeTemplateId',
                name: 'product/addnosalesattribute',
                component: () => import('../views/admin/product/attribute/NoSalesAttributeAdd.vue'),
                meta: {
                    routerPath: 'attributetemplate'
                }
            },
            {
                path: 'product/updatenosalesattribute/:attributeId',
                name: 'product/updatenosalesattribute',
                component: () => import('../views/admin/product/attribute/NoSalesAttributeUpdate.vue'),
                meta: {
                    routerPath: 'attributetemplate'
                }
            },
            {
                path: 'product/addsalesattribute/:attributeTemplateId',
                name: 'product/addsalesattribute',
                component: () => import('../views/admin/product/attribute/SalesAttributeAdd.vue'),
                meta: {
                    routerPath: 'attributetemplate'
                }
            },
            {
                path: 'product/updatesalesattribute/:attributeId',
                name: 'product/updatesalesattribute',
                component: () => import('../views/admin/product/attribute/SalesAttributeUpdate.vue'),
                meta: {
                    routerPath: 'attributetemplate'
                }
            },
            {
                path: 'product/salesattributemanage/:attributeTemplateId',
                name: 'product/salesattributemanage',
                component: () => import('../views/admin/product/attribute/SalesAttributeManage.vue'),
                meta: {
                    routerPath: 'attributetemplate'
                }
            },
            {
                path: 'product/brandmanage',
                name: 'product/brandmanage',
                component: () => import('../views/admin/product/brand/BrandManage.vue'),
                meta: {
                    routerPath: 'brandmanage'
                }
            },
            {
                path: 'product/addbrand',
                name: 'product/addbrand',
                component: () => import('../views/admin/product/brand/BrandAdd.vue'),
                meta: {
                    routerPath: 'brandmanage'
                }
            },
            {
                path: 'product/updatebrand/:id',
                name: 'product/updatebrand',
                component: () => import('../views/admin/product/brand/BrandUpdate.vue'),
                meta: {
                    routerPath: 'brandmanage'
                }
            },
            {
                path: 'auth/adminlist',
                name: 'auth/adminlist',
                component: () => import('../views/admin/auth/AdminList.vue'),
                meta: {
                    routerPath: 'adminlist'
                }
            },
            {
                path: 'auth/userlist',
                name: 'auth/userlist',
                component: () => import('../views/admin/auth/UserList.vue'),
                meta: {
                    routerPath: 'userlist'
                }
            },
            {
                path: 'auth/rolelist',
                name: 'auth/rolelist',
                component: () => import('../views/admin/auth/RoleList.vue'),
                meta: {
                    routerPath: 'rolelist'
                }
            },
            {
                path: 'auth/permissionlist',
                name: 'auth/permissionlist',
                component: () => import('../views/admin/auth/PermissionList.vue'),
                meta: {
                    routerPath: 'permissionlist'
                }
            },
            {
                path: 'auth/permissionassignment',
                name: 'auth/permissionassignment',
                component: () => import('../views/admin/auth/PermissionAssignment.vue'),
                meta: {
                    routerPath: 'permissionassignment'
                }
            },{
                path: 'order/OrderList',
                component:() =>import('../views/admin/order/OrderListView'),
                meta:{
                    title:'尔玉管理平台——订单列表'
                }
            },
            {
                path: 'order/AwaitSend',
                component:() =>import('../views/admin/order/AwaitSendView'),
                meta:{
                    title:'尔玉管理平台——待发货'
                }
            },
            {
                path: 'order/DueIn',
                component:() =>import('../views/admin/order/AwaitTakeView'),
                meta:{
                    title:'尔玉管理平台——待签收'
                }
            },
            {
                path: 'order/Accomplish',
                component:() =>import('../views/admin/order/AccomplishView'),
                meta:{
                    title:'尔玉管理平台——已完成'
                }
            }
        ]
    },
    {
        path: '/user',
        component: () => import('../views/user/UserView.vue'),
        redirect: '/user/reg',
        children: [
            {
                path: 'reg',
                component: () => import('../views/user/UserRegView.vue'),
                meta: {
                    title: '玺玛特Xi-mart——用户注册'
                }
            },
            {
                path: 'login',
                component: () => import('../views/user/UserLoginView.vue'),
                meta: {
                    title: '玺玛特Xi-mart——用户登录'
                }
            },
            {
                path: 'list',
                component: () => import('../views/user/UserListView.vue'),
                meta: {
                    title: '玺玛特Xi-mart——完善用户信息'
                }
            }

        ]
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    next();
})

export default router
